package edu.umich.PowerTutor.phone;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class M110sConstants extends DreamConstants{
	  protected int screenWidth;
	  protected int screenHeight;

	  public M110sConstants(Context context) {
	    super(context);
	    DisplayMetrics metrics = new DisplayMetrics();
	    WindowManager windowManager =
	        (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
	    windowManager.getDefaultDisplay().getMetrics(metrics);
	    screenWidth = metrics.widthPixels;
	    screenHeight = metrics.heightPixels;
	  }

	  public String modelName() {
	    return "M110S";
	  }

	  public double maxPower() {
	    return 2800;
	  }

	  //Desire Power MOdel
	  public double lcdBrightness() {
		return 0.157;  
	}

	  public double lcdBacklight() {
	    throw new RuntimeException("lcdBacklight() for Desire which has no LCD " +
	                               "display");
	  }

	  //Desire Power MOdel
	  public double oledBasePower() {
	    return 201.458; // This incorporates all the constant component in the model.
	  }

	  private static final double[] arrayChannelPower = {
	      3.0647e-006, 4.4799e-006, 6.4045e-006};
	  public double[] oledChannelPower() {
	    return arrayChannelPower;
	  }

	  public double oledModulation() {
	    return 1.7582e-006;
	  }

	  //997Mhza에서 밖에 동작하지 않기 떄문에 이 mode를 사용한다.
	  //(Nexus One) 이때의 주기는 7.1이다.  5.4818(원래값)
	  private static final double[] arrayCpuPowerRatios = {1.1273, 1.5907, 1.8736,
	      2.1745, 2.6031, 2.9612, 3.1373,3.4513, 3.9073 ,4.1959, 4.6492, 7.1};
	  public double[] cpuPowerRatios() {
	    return arrayCpuPowerRatios;
	  }

	  private static final double[] arrayCpuFreqs = {245, 384, 460, 499, 576, 614,
	      653, 691, 768, 806, 845, 998};
	  public double[] cpuFreqs() {
	    return arrayCpuFreqs;
	  }

	  public double audioPower() {
		    return 0;
	  }

	  private static final double[] arrayGpsStatePower = {0.0, 17.5, 268.94};
	  public double[] gpsStatePower() {
	    return arrayGpsStatePower;
	  }

	  public double gpsSleepTime() {
	    return 6.0;
	  }

	  public double wifiLowPower() {
	    return 34.37;
	  }

	  public double wifiHighPower() {
	    return 404.46 ;
	  }

	  public double wifiLowHighTransition() {
	    return 15;
	  }

	  public double wifiHighLowTransition() {
	    return 8;
	  }

	  private static final double[] arrayWifiLinkRatios = {
	    47.122645, 46.354821, 43.667437, 43.283525, 40.980053, 39.44422, 38.676581,
	    34.069637, 29.462693, 20.248805, 11.034917, 6.427122
	  };
	  public double[] wifiLinkRatios() {
	    return arrayWifiLinkRatios;
	  }

	  private static final double[] arrayWifiLinkSpeeds = {
	    1, 2, 5.5, 6, 9, 11, 12, 18, 24, 36, 48, 54
	  };
	  public double[] wifiLinkSpeeds() {
	    return arrayWifiLinkSpeeds;
	  }

	  public String threegInterface() {
	    return "rmnet0";
	  }

	  public double threegIdlePower(String oper) {
	    if(OPER_TMOBILE.equals(oper)) {
	      return 10;
	    }
	    return 10; // Return the worst case for unknown operators.
	  }

	  public double threegFachPower(String oper) {
	    if(OPER_TMOBILE.equals(oper)) {
	      return 405.81;
	    }
	    return 405.81; // Return the worst case for unknown operators.
	  }

	  public double threegDchPower(String oper) {
	    if(OPER_TMOBILE.equals(oper)) {
	      return 902.03;
	    }
	    return 902.03; // Return the worst case for unknown operators.
	  }

	  public double getMaxPower(String componentName) {
	    if("OLED".equals(componentName)) {
	      double[] channel = oledChannelPower();
	      return oledBasePower() + 255 * screenWidth * screenHeight *
	             (channel[0] + channel[1] + channel[2] - oledModulation());
	    }
	    return super.getMaxPower(componentName);
	  }
}
